package com.macasa.panel.entity.impl;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Version;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import com.google.common.base.Objects;
import com.macasa.enumerations.CronType;
import com.macasa.panel.common.utils.CastHelpers;
import com.macasa.panel.entity.api.AbstractModel;
import com.macasa.panel.entity.api.ICronLock;

@Entity
@Table(name = "cron_lock")
@SequenceGenerator(name = "CronLock_SEQ", sequenceName = "CronLockIdSeq", initialValue = 1)
@Getter
@Setter
@ToString
public class CronLock extends AbstractModel<Integer> implements ICronLock {

	/**
	 * The Constant serialVersionUID
	 */
	@Version
	private static final long	serialVersionUID	= -4870506987500159475L;

	@Id
	@Column(name = "cron_lock_id", nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "CronLock_SEQ")
	private Integer				id;

	@Enumerated(EnumType.STRING)
	@Column(name = "type", nullable = false)
	private CronType			type;

	@Override
	public boolean equals(final Object obj) {

		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof CronLock)) {
			return false;
		}

		final CronLock other = CastHelpers.cast(obj, CronLock.class);

		return Objects.equal(this.id, other.id) && Objects.equal(this.type, other.type);
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(this.id, this.type);
	}
}
